]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
main: Override global logError() function
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 21 Dec 2023 17:43:17 +0000 (18:43 +0100)
committerMarge Bot <marge-bot@gnome.org>
Thu, 21 Dec 2023 19:17:32 +0000 (19:17 +0000)
logError() prints an exception with an optional prefix, and is
used fairly commonly through-out the code base.

The problem is that by being defined in gjs, it uses "Gjs" as the
GLib log domain, not our own as expected.

Address this by adding a small override that implements the function
with console.error().

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3072>

js/ui/main.js

index ad6d3d61137ee475600584fe761827dc0045d24f..3781c9607f7a76daa13c1d9c6b10486d275f7fa4 100644 (file)
@@ -143,6 +143,16 @@ function _sessionUpdated() {
 /** @returns {void} */
 export async function start() {
     globalThis.log = console.log;
+    globalThis.logError = function (err, msg) {
+        const args = [err];
+        try {
+            // toString() can throw
+            if (msg)
+                args.unshift(`${msg}:`);
+        } catch (e) {}
+
+        console.error(...args);
+    };
 
     // Chain up async errors reported from C
     global.connect('notify-error', (global, msg, detail) => {